<?php
require_once("include/global.php");
@session_start();

function ShowMenu() {
	global $mysql;
	
	print <<<HTML
	<div id="left"></div>
	<div id="right">
	<ul>
	<li id="home"><a href="./" class="menu" title="主页">Home</a></li>
HTML;
	if($_SESSION['admin'] == 'admin'){
		echo "<li id=\"login\"><a class='menu' href='./admin/main.php' title=\"管理\">Admin</a></li>\n";
	}else{
		echo "<li id=\"login\"><a class='menu' href=\"javascript:document.getElementById('ShowLogin').style.display='block';void 0;\" title=\"登陆\">Login</a></li>\n";
	}
	
	$sql = "SELECT * FROM blog_category order by cate_Order";
	$rss = $mysql->select($sql);
	foreach( $rss as $rs )
	{
		print <<<HTML
	<li><a href="./?do=ShowCategory&page=1&cate_ID=$rs[cate_ID]" class="menu" title=$rs[cate_Intro] >$rs[cate_Name]</a></li>\n
HTML;
	} 
	print <<<HTML
	<li id="skin"><a href="javascript:ChangeSkin();void 0;" class="menu" title="换肤">Style</a></li>
	</ul>\n\t</div>\n
HTML;
}

function ShowHeader() {
	print <<<HTML
  	\r  <div id="header">
	<div id="blogname"><h2>Nonsenser&#39;s Evil</h2>
		<div id="blogtitle">I am just a Nonsenser</div>
	</div>
	<div id="ShowMenu">\n
HTML;
		ShowMenu();
	echo "\t</div>\n  </div>\n";
}

function ShowSidebar() {
	global $mysql;
	
	echo "\n  <div id=\"sidebar\">\n";
	/*	ShowWelcome 显示欢迎字幕	*/
	print <<<HTML
	<div id="Welcome">
		<div id="title" class="sidetitle">I have found these words:</div>
		<div id="content">Whenever you need a helping hand,it is at the end of your arm. And as you get older,you must remember that you have a second hand,the first one is to help yourself,the second is to help the others.</div>
	</div>\n
HTML;
	
	/*	ShowImage 显示图片	*/
	print <<<HTML
	<div id="ShowPhoto">
		<div id="title" class="sidetitle">Photo</div>
		<div id="photo">
		<a href="javascript:void 0;" ><img id="thephoto" width=160 height=160 src='attach/images/default.jpg' style="border:1px #008000 solid;" /></a>
		<script src="include/getimages.php"></script>	  
		<script type="text/javascript">
			var curimg=0
			function rotateimages(){
				var photo = document.getElementById("thephoto");
				photo.onclick = function(){
				window.open("attach/images/"+galleryarray[curimg],"Photo","width=400,height=350,status=no,resizable=no");
				}
			photo.src = "attach/images/"+galleryarray[curimg];
			curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
			}
			setInterval("rotateimages()", 2500)
		</script>
		</div>
	</div>\n
HTML;

	/*	ShowRecent 显示最新文章	*/
	print <<<HTML
	\n\t<div id="ShowRecent">
	<div  class="sidetitle">Recent Articles</div>
	<div  class="sidecontent">
	<ul>\n
HTML;
	$sql = "SELECT * FROM blog_article ORDER  BY log_PostTime desc limit 0,10";
	$rss = $mysql->select($sql);
	foreach( $rss as $rs )
	{
		$title = $rs[log_Title];
		print "\t<li id='$rs[log_ID]'><a href='./?do=ShowSpecify&log_ID=$rs[log_ID]' title='$rs[log_Author] Post @ ".strftime("%B %d,%Y,%H:%M %p ",$rs[log_PostTime])."$rs[log_Title]'>$title</a></li>\n";
	}
	print "\t</ul>\n\t</div>\n\t</div>\n";

	/*	ShowComment 显示评论	*/
	print <<<HTML
	\n\t<div id="ShowComment">
	<div class="sidetitle">Recent Comments</div>
	<div class="sidecontent">
	<ul>\n
HTML;
	$sql = "SELECT * FROM blog_comment ORDER  BY comm_PostTime desc limit 0,10";
	$rss = $mysql->select($sql);
	foreach( $rss as $rs )
	{
		$content = substr($rs[comm_Content],0,25);
        $time = strftime("%B %d,%Y,%H:%M %p",$rs[comm_PostTime]);
		print <<<HTML
        <li id='$rs[comm_ID]'>
        <a href='./?do=ShowSpecify&log_ID=$rs[comm_LogID]#$rs[comm_ID]' title='$rs[comm_Author] Post @ $time $rs[comm_Content]'>$content</a>
        </li>\n
HTML;
	}
	print "\t</ul>\n\t</div>\n\t</div>\n";

	/*	ShowSearch 显示搜索	*/
    print <<<HTML
    \n\t<div id="Search">
        <div id="title" class="sidetitle">Search</div>
        <div id="content" class="sidecontent">
        <script type="text/javascript" language="javascript">
            var domain = "www.nonsenser.com" ;
            var GoogleUrl;
            function GetSearchUrl( qsform )
            {
                GoogleUrl ="site:" + domain + " " + qsform.querystring.value;
            }
        </script>
        <form action="javascript:window.open('http://www.google.com/search?q='+escape(GoogleUrl));void 0;" method="get" name="search" onsubmit="GetSearchUrl(this);">
            <input name="querystring" type="text" size="14" />&nbsp;<button type="submit">Search</button>
        </form>
        </div>
	</div>\n
HTML;

	/*	ShowLink 显示友情链接 */
	
    
    print <<<HTML
	\n\t<div id="ShowLink">
	<div id="title" class="sidetitle">Friend Links</div>
	<div id="content" class="sidecontent">
	<ul name="links">\n
HTML;
	$sql = "SELECT * FROM blog_link ORDER  BY link_Order";
	$rss = $mysql->select($sql);
	foreach( $rss as $rs )
		echo "\t<li id='$rs[link_ID]'><a href='$rs[link_Url]' title='$rs[link_Name]' target='_blank'>$rs[link_Name]</a></li>\n";
	echo "\t</ul>\n\t</div>\n\t</div>\n";
    
	/*	ShowArchive 显示归档	*/
    print <<<HTML
    \n\t<div id="ShowArchive">
	<div id='title' class='sidetitle'>Archive</div>
	<div id='content' class='sidecontent'>
	<ul>\n
HTML;
	$now = time();
	$sql = "SELECT log_PostTime from blog_article order by log_PostTime";
	$rs = $mysql->fetch_one_array($sql);
	if($rs)
	{
	   $oldest = $rs[log_PostTime];
	   //echo $oldest."<br>";
	   //echo $sql."<br>"; 
	   $firstyear  = strftime("%Y",$oldest);
	   if(!$firstyear){ $firstyear = strftime("%Y",$now); }
	   $lastyear   = strftime("%Y",$now);
	   $firstmonth = strftime("%m",$oldest);
	   if(!$firstmonth){ $firstmonth = strftime("%m", $now); }
	   $lastmonth  = strftime("%m",$now);
	   //echo $firstmonth."<br>";
	   //echo $lastmonth."<br>";
	   $months = ($lastyear-$firstyear)*12+($lastmonth-$firstmonth);
	   //echo $months;
	   $month = $firstmonth;
       //echo $month;
	   $year  = $firstyear;
	   //echo $firstyear."</br>";
	   //echo $lastyear;
	   do{
            if($month > 12)
            { $year++ ; $month=1 ; }
            
            $start = strtotime($year."-".$month."-1");
            if($month == 12)
            { $end = strtotime(($year+1)."-1-1"); }
            else{ $end   = strtotime($year."-".($month+1)."-1"); }
            
            $sql = "select count(*) from blog_article where log_PostTime >= ".$start." and log_PostTime < ".$end;
            $query = $mysql->query($sql);
            $rs = $mysql->fetch_array($query, MYSQL_NUM);
            $num = $rs[0];
            if($month < 10) $month = '0'.$month;
            if($num>0)
                echo "\t<li><a href='./?do=ShowCategory&page=1&date=$year$month'>".$year."年".$month."月</a> [$num] </li>\n";
            $month ++;
	   }while(($month <= $lastmonth) || ($year < $lastyear));
	}
	echo "\t</ul>\n\t</div>\n\t</div>\n  </div>\n";
}

function ShowLogin()
{
	print <<<HTML
	\n  <div id="ShowLogin">
        <form method="post" action="javascript:void 0;" name="login" onsubmit="javascript:PostLogin(this);document.getElementById('ShowLogin').style.display='none'; void 0;">
        <table cellpadding="0" cellspacing="0"  width="100%">
        <tr height="25" align="center">
        <td class="login_title" colspan="2" width="100%"><span>User Login</span></td>
        <tr height="30">
        <td width="100" align="right">Username:</td>
        <td align="left">
        <input class="userpass" name="username" size="16" type="text" maxlength="20" /></td>
        </tr>
        <tr height="30">
        <td width="100" align="right">Password:</td>
        <td align="left">
        <input class="userpass" name="password" size="16" type="password" maxlength="20" /></td>
        </tr>
        <tr height="30"><td colspan="2" width="100%">
        <button type="submit">Summit</button>&nbsp;&nbsp;<button type="button" onclick="document.getElementById('ShowLogin').style.display='none';">Cancel</button>
        </td></tr>
        </table>
        </form>
  </div>\n
HTML;
}

function ShowFooter()
{
	print <<<HTML
	\n  <div id="footer">
        <p>
        <center>Programed By: <a href="javascript:void 0;">Nonsenser</a> CopyLeft&copy;<strong><a href="http://www.nonsenser.com/">
        <font color=#0000ff>Nonsenser.</font><font color=#ffaa00>Com</font></a></strong> 2006
        <br />
        <script src='http://s46.cnzz.com/stat.php?id=176794&web_id=176794' language='JavaScript' charset='gb2312'></script>
        <br />
        <a href="http://www.miibeian.gov.cn" target="_blank" style="font-size:12px">鄂ICP备06011952号</a></center>
        </p>
  </div>\n
HTML;
}

?>